package com.ruoyi.his.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.his.domain.HisMedicalRecord;
import com.ruoyi.his.service.IHisMedicalRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药方Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@RestController
@RequestMapping("/his/record")
public class HisMedicalRecordController extends BaseController
{
    @Autowired
    private IHisMedicalRecordService hisMedicalRecordService;




    /**
     * 新增药方
     */
    @PostMapping(value = "/addyf")
    public AjaxResult addyf(@RequestBody HisMedicalRecord data)
    {
        return toAjax(hisMedicalRecordService.insertHisMedicalRecord(data));
    }









    /**
     * 查询药方列表
     */
    @PreAuthorize("@ss.hasPermi('his:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisMedicalRecord hisMedicalRecord)
    {
        startPage();
        List<HisMedicalRecord> list = hisMedicalRecordService.selectHisMedicalRecordList(hisMedicalRecord);
        return getDataTable(list);
    }

    /**
     * 导出药方列表
     */
    @PreAuthorize("@ss.hasPermi('his:record:export')")
    @Log(title = "药方", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HisMedicalRecord hisMedicalRecord)
    {
        List<HisMedicalRecord> list = hisMedicalRecordService.selectHisMedicalRecordList(hisMedicalRecord);
        ExcelUtil<HisMedicalRecord> util = new ExcelUtil<HisMedicalRecord>(HisMedicalRecord.class);
        return util.exportExcel(list, "药方数据");
    }

    /**
     * 获取药方详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hisMedicalRecordService.selectHisMedicalRecordById(id));
    }

    /**
     * 新增药方
     */
    @PreAuthorize("@ss.hasPermi('his:record:add')")
    @Log(title = "药方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HisMedicalRecord hisMedicalRecord)
    {
        return toAjax(hisMedicalRecordService.insertHisMedicalRecord(hisMedicalRecord));
    }

    /**
     * 修改药方
     */
    @PreAuthorize("@ss.hasPermi('his:record:edit')")
    @Log(title = "药方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisMedicalRecord hisMedicalRecord)
    {
        return toAjax(hisMedicalRecordService.updateHisMedicalRecord(hisMedicalRecord));
    }

    /**
     * 删除药方
     */
    @PreAuthorize("@ss.hasPermi('his:record:remove')")
    @Log(title = "药方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hisMedicalRecordService.deleteHisMedicalRecordByIds(ids));
    }
}
